﻿// -----------------------------------------------------------------------
// <copyright file="FileRankPhotos.cs" company="Hewlett-Packard">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Ex3.Logic
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    using System.Xml.Serialization;
    using FacebookWrapper.ObjectModel;
    using Repository;

    /// <summary>
    /// Represents a list of FileRank
    /// </summary>
    public class FileRankPhotos
    {
        public List<FileRank> FilePhotos { get; private set; }
        
        public FileRankPhotos()
        {
            this.FilePhotos = new List<FileRank>();
        }

        public FileRankPhotos(RankPhotos rankPhotos)
        {
            this.FilePhotos = new List<FileRank>();
            
            foreach (RankedPhoto currentPhoto in rankPhotos)
            {
                this.FilePhotos.Add(new FileRank(currentPhoto.ID, currentPhoto.RankedStars, currentPhoto.URL));
            }
        }

        public void Save(User i_LoggedInUser)
        {
            RepositoryFactory repository = FactoryMaker.GetFactory(i_LoggedInUser);
            repository.CreateFileRankRepository().SaveRankPhotos(this.FilePhotos);
        }

        public void Load(User i_LoggedInUser)
        {
            RepositoryFactory repository = FactoryMaker.GetFactory(i_LoggedInUser);
            this.FilePhotos = repository.CreateFileRankRepository().LoadRankPhotos();
        }
    }
}
